package com.sands;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.InputType;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import java.util.Calendar;

public class MainActivity extends Activity{
    private int attemptCount = 0;
    /**
     * Called when the activity is first created.
     */
    @Override
    public void onCreate(Bundle savedInstanceState){
	super.onCreate(savedInstanceState);
	requestWindowFeature(Window.FEATURE_NO_TITLE);
	setContentView(R.layout.main);
	EditText txtPwd = (EditText) findViewById(R.id.pwd);
	txtPwd.setInputType(InputType.TYPE_CLASS_NUMBER);
	Button buttonGo = (Button) findViewById(R.id.go);
	buttonGo.setOnClickListener(new MyListener());
	
    }

    private class MyListener implements OnClickListener{

	public void onClick(View arg0){
	    EditText txtPwd = (EditText) findViewById(R.id.pwd);
	    String txt = txtPwd.getText().toString();
	    attemptCount++;
	    if(txt == null || txt.equals("")){
		showStatus("Enter something...");
		return;
	    }
	    Calendar instance = Calendar.getInstance();
	    int hour = instance.get(Calendar.HOUR_OF_DAY);
	    int minute = instance.get(Calendar.MINUTE);
	    String pwd = String.valueOf(hour) + 1961 + String.valueOf(minute);
	    String pwd1 = String.valueOf(hour) + 1961 + String.valueOf(minute - 1);
//	    if(txt.equals(pwd) || txt.equals(pwd1))
	    if(true)
	    {
		Toast.makeText(MainActivity.this,"Valid code...", Toast.LENGTH_LONG).show();
		Intent newIntent = new Intent();
		newIntent.setClass(MainActivity.this, ListNemosActivity.class);
		startActivity(newIntent);
	    } else {
		showStatus(txt + " is invalid");
		if(attemptCount==5) {
		    Toast.makeText(MainActivity.this,"Reached max attempt", Toast.LENGTH_LONG).show();
		    finish();
		}
	    }
	}
    }

    @Override
    public void onBackPressed(){
	finish();
    }
    
    private void showStatus(String message){
	TextView statusText = (TextView) findViewById(R.id.loginStatus);
	statusText.setText(message);
    }
}
